<<<<<<< HEAD
package com.wyz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wyz.common.AutoLog;
import com.wyz.common.ResultVo;
import com.wyz.dto.UpdateScoreDto;
import com.wyz.entity.ScoreEntity;
import com.wyz.service.ScoreService;

import com.wyz.vo.StudentScoreVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Slf4j
@RestController
@RequestMapping("/score")
public class  ScoreController {

    @Resource
    private ScoreService scoreService;
    @AutoLog("进入成绩管理页面")
    @GetMapping("/queryScoreByPage")

    public ResultVo<List<StudentScoreVo>> queryCourseTableByPage(){
        log.info("查询成绩信息请求");
        List<StudentScoreVo> studentScoreVoS = scoreService.getStudentScoreList();
        log.info("查询成绩信息响应,参数:{}", studentScoreVoS);
        return new ResultVo<>(200,"ok",studentScoreVoS);

    }
  /*  @GetMapping("/queryScoreByPage/{page}")
    public ResultVo<Map<String,Object>> queryStudentByPage(@PathVariable("page") int page) {
        log.info("分页查询学生成绩信息请求,参数:{}", page);
        IPage<StudentScoreVo> studentScoreListPage = scoreService.getStudentScoreListByPage(page);
        List<StudentScoreVo> studentScoreList = studentScoreListPage.getRecords();//获取分页查询结果
        int total = (int)studentScoreListPage.getPages();//获取总页数
        //构造分页页码列表
        List<Integer> pageList = new ArrayList<>();
        for (int i = 1; i <= total ; i++) {
            pageList.add(i);
        }
        log.info("pageList:{}",pageList);

        //使用Map封装响应的多个数据
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("studentScoreList",studentScoreList);
        resultMap.put("pageList",pageList);

        log.info("获取分页学生成绩信息列表响应", resultMap);

        return new ResultVo<>(200,"ok",resultMap);
    }*/

    @AutoLog("查询学生成绩信息")
    @GetMapping("/queryScoreById/{studentId}")
    public ResultVo<List<StudentScoreVo>> studentGetScoresByStudentId(@PathVariable Integer studentId) {
        log.info("查询学生ID为{}的成绩详情", studentId);
        try{
            List<StudentScoreVo> studentScoreList = scoreService.getScoresByStudentId(studentId);
            return new ResultVo<>(200,"ok",studentScoreList);

        }catch (Exception e) {
            return ResultVo.fail();
        }
    }
    //增加学生成绩
  /*  @PostMapping("/addStudentScore")
    public ResultVo<Boolean> addStudentScore(@RequestBody ScoreEntity scoreEntity) {
        log.info("增加学生成绩" + scoreEntity);
        try {
            boolean result = scoreService.addScore(scoreEntity);
            if(result){
                log.info("增加学生成绩成功:{}", scoreEntity);
                return new ResultVo<>(200,"ok",true);}
            else{
                log.info("增加学生成绩失败:{}", scoreEntity);
                return ResultVo.fail();
            }
        } catch (Exception e) {
            return ResultVo.fail();
        }
    }
*/


    @PostMapping("/addStudentScore")
    @AutoLog("增加学生成绩")
    public ResultVo<Boolean> addStudentScore(@RequestBody ScoreEntity scoreEntity) {
        log.info("增加学生成绩" + scoreEntity);
        try {
            boolean result = scoreService.addScore(scoreEntity);
            if(result){
                log.info("增加学生成绩成功:{}", scoreEntity);
                return new ResultVo<>(200,"ok",true);}
            else{
                log.info("增加学生成绩失败:{}", scoreEntity);
                return ResultVo.fail();
            }
        } catch (Exception e) {
            return ResultVo.fail();
        }
    }
    @AutoLog("修改学生成绩")
    @PutMapping ("/teacher/update")
    public ResultVo<Boolean> update(@RequestBody UpdateScoreDto updateScoreDto ) {
        log.info("修改学生成绩: " + updateScoreDto);
        try{
            Boolean result = scoreService.updateScore(updateScoreDto); // 调用服务层更新成绩
            return  new ResultVo<>(200,"ok",result);
        }catch (Exception e) {
            return ResultVo.fail();
        }
    }
    @AutoLog("查询课程id")
    @GetMapping ("/queryScoreByCourseId/{courseId}")
    public ResultVo<List<StudentScoreVo> >getScoresByCourseId(@PathVariable Integer courseId) {
        log.info("查询课程ID为{}的成绩", courseId);
        try{
            List<StudentScoreVo> studentScoreList= scoreService.getScoresByCourseId(courseId);
            return new ResultVo<>(22,"ok",studentScoreList);
        }
        catch (Exception e) {
            return ResultVo.fail();
        }
    }
  /*
    @GetMapping("/teacher/query/{studentId}")
    public ResultVo<List<StudentScoreVo> >teacherGetScoresByStudentId(@PathVariable Integer studentId) {
        log.info("查询学生ID为{}的成绩详情", studentId);
        try{
            List<StudentScoreVo> studentScoreList = scoreService.getScoresByStudentId(studentId);
            return new ResultVo<>(200,"ok",studentScoreList);
        }
        catch (Exception e) {
            return ResultVo.fail();
        }
    }*/

    /*@GetMapping("teacher/scores/{name}")
    public ResultVo<List<StudentScoreVo> >getScoresByStudentName(@PathVariable String name) {
        log.info("模糊查询学生姓名为{}的成绩", name);
        try{
            List<StudentScoreVo> studentScoreList = scoreService.getScoresByStudentName(name);
            return new ResultVo<>(200,"ok",studentScoreList);
        }
        catch (Exception e) {
            return ResultVo.fail();
        }
    }*/
}
=======
package com.wyz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wyz.common.AutoLog;
import com.wyz.common.ResultVo;
import com.wyz.dto.UpdateScoreDto;
import com.wyz.entity.ScoreEntity;
import com.wyz.service.ScoreService;

import com.wyz.vo.StudentScoreVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Slf4j
@RestController
@RequestMapping("/score")
public class  ScoreController {

    @Resource
    private ScoreService scoreService;
    @AutoLog("进入成绩管理页面")
    @GetMapping("/queryScoreByPage")

    public ResultVo<List<StudentScoreVo>> queryCourseTableByPage(){
        log.info("查询成绩信息请求");
        List<StudentScoreVo> studentScoreVoS = scoreService.getStudentScoreList();
        log.info("查询成绩信息响应,参数:{}", studentScoreVoS);
        return new ResultVo<>(200,"ok",studentScoreVoS);

    }
  /*  @GetMapping("/queryScoreByPage/{page}")
    public ResultVo<Map<String,Object>> queryStudentByPage(@PathVariable("page") int page) {
        log.info("分页查询学生成绩信息请求,参数:{}", page);
        IPage<StudentScoreVo> studentScoreListPage = scoreService.getStudentScoreListByPage(page);
        List<StudentScoreVo> studentScoreList = studentScoreListPage.getRecords();//获取分页查询结果
        int total = (int)studentScoreListPage.getPages();//获取总页数
        //构造分页页码列表
        List<Integer> pageList = new ArrayList<>();
        for (int i = 1; i <= total ; i++) {
            pageList.add(i);
        }
        log.info("pageList:{}",pageList);

        //使用Map封装响应的多个数据
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("studentScoreList",studentScoreList);
        resultMap.put("pageList",pageList);

        log.info("获取分页学生成绩信息列表响应", resultMap);

        return new ResultVo<>(200,"ok",resultMap);
    }*/

    @AutoLog("查询学生成绩信息")
    @GetMapping("/queryScoreById/{studentId}")
    public ResultVo<List<StudentScoreVo>> studentGetScoresByStudentId(@PathVariable Integer studentId) {
        log.info("查询学生ID为{}的成绩详情", studentId);
        try{
            List<StudentScoreVo> studentScoreList = scoreService.getScoresByStudentId(studentId);
            return new ResultVo<>(200,"ok",studentScoreList);

        }catch (Exception e) {
            return ResultVo.fail();
        }
    }
    //增加学生成绩
  /*  @PostMapping("/addStudentScore")
    public ResultVo<Boolean> addStudentScore(@RequestBody ScoreEntity scoreEntity) {
        log.info("增加学生成绩" + scoreEntity);
        try {
            boolean result = scoreService.addScore(scoreEntity);
            if(result){
                log.info("增加学生成绩成功:{}", scoreEntity);
                return new ResultVo<>(200,"ok",true);}
            else{
                log.info("增加学生成绩失败:{}", scoreEntity);
                return ResultVo.fail();
            }
        } catch (Exception e) {
            return ResultVo.fail();
        }
    }
*/


    @PostMapping("/addStudentScore")
    @AutoLog("增加学生成绩")
    public ResultVo<Boolean> addStudentScore(@RequestBody ScoreEntity scoreEntity) {
        log.info("增加学生成绩" + scoreEntity);
        try {
            boolean result = scoreService.addScore(scoreEntity);
            if(result){
                log.info("增加学生成绩成功:{}", scoreEntity);
                return new ResultVo<>(200,"ok",true);}
            else{
                log.info("增加学生成绩失败:{}", scoreEntity);
                return ResultVo.fail();
            }
        } catch (Exception e) {
            return ResultVo.fail();
        }
    }
    @AutoLog("修改学生成绩")
    @PutMapping ("/teacher/update")
    public ResultVo<Boolean> update(@RequestBody UpdateScoreDto updateScoreDto ) {
        log.info("修改学生成绩: " + updateScoreDto);
        try{
            Boolean result = scoreService.updateScore(updateScoreDto); // 调用服务层更新成绩
            return  new ResultVo<>(200,"ok",result);
        }catch (Exception e) {
            return ResultVo.fail();
        }
    }
    @AutoLog("查询课程id")
    @GetMapping ("/queryScoreByCourseId/{courseId}")
    public ResultVo<List<StudentScoreVo> >getScoresByCourseId(@PathVariable Integer courseId) {
        log.info("查询课程ID为{}的成绩", courseId);
        try{
            List<StudentScoreVo> studentScoreList= scoreService.getScoresByCourseId(courseId);
            return new ResultVo<>(22,"ok",studentScoreList);
        }
        catch (Exception e) {
            return ResultVo.fail();
        }
    }
  /*
    @GetMapping("/teacher/query/{studentId}")
    public ResultVo<List<StudentScoreVo> >teacherGetScoresByStudentId(@PathVariable Integer studentId) {
        log.info("查询学生ID为{}的成绩详情", studentId);
        try{
            List<StudentScoreVo> studentScoreList = scoreService.getScoresByStudentId(studentId);
            return new ResultVo<>(200,"ok",studentScoreList);
        }
        catch (Exception e) {
            return ResultVo.fail();
        }
    }*/

    /*@GetMapping("teacher/scores/{name}")
    public ResultVo<List<StudentScoreVo> >getScoresByStudentName(@PathVariable String name) {
        log.info("模糊查询学生姓名为{}的成绩", name);
        try{
            List<StudentScoreVo> studentScoreList = scoreService.getScoresByStudentName(name);
            return new ResultVo<>(200,"ok",studentScoreList);
        }
        catch (Exception e) {
            return ResultVo.fail();
        }
    }*/
}
>>>>>>> be516e15a35375b38cf973b1ce88c92dd1ceba03
